for (let v of b) {
    console.log(v);
};

for (let v in b) {
    console.log(v, b[v]);
}

var cat = { 
    say() { console.log("meow~"); }, 
    jump() { console.log("jump"); } 
}
var tiger = Object.create(cat, { 
    say: { 
            writable: true, 
            configurable: true, 
            enumerable: true, 
            value: function () { console.log("roar!"); } 
        } 
    }
)

var anotherCat = Object.create(cat); 
anotherCat.say(); 
var anotherTiger = Object.create(tiger); 
anotherTiger.say();


function Cat(){
    this.name="猫";
    this.jump = function(){
        console.log(this.name,'跳跃');
    }
}

let c = new Cat();
c.name = '花花';
c.jump()

let b = new Cat();
b.jump()


function Tiger(){

}

Tiger.prototype.name = "虎";
Tiger.prototype.jump = function(){
    console.log(this.name,'跳跃')
}

let c = new Tiger();
c.name = '东北虎';
c.jump()

let b = new Tiger();
b.jump()


function cls(){    
    this.a = 100;
    //直接返回一个对象    
    return {        
        getValue:() => this.a    
    }
}
var o = new cls;
o.getValue(); //100//a在外面永远无法访问到


var dv = document.getElementById('help');
dv.scrollIntoView(true);


class MyNumber{
    valueOf(){
        return 11
    }
    toString(){
        return 33
    }
}

class MyNumber1{
    valueOf(){
        return NaN;
    }
    toString(){
        return 33
    }
}

class MyNumber2{
    toString(){
        return 33
    }
}

function hello(){
    console.log('hello,',arguments)
}

function hello(name,message){
    console.log(arguments[0]+','+message)
}

var name ='rose'
function change(name){
    name = 'jack';
    console.log(name)
}
console.log(name)

var age = 33;
function changeInt(age){
    age = age +10;
    console.log(age)
}
changeInt(age);
console.log(age)

class Cat {
    constructor(){
        this.name = '猫'
    }
}

function changeCat(cat){
    cat.name = '小花猫'
    console.log(cat)
}

var cat = new Cat();
changeCat(cat);
console.log(cat)


if(true){
    var jj = 10;
}
alert(jj);if(true){
    var jj = 10;
}
alert(jj);

"use strict"
function invoke(){
    say();
}

function say(){
    console.log(arguments);
    console.log(arguments.callee);  // 指针，指向函数 say
    console.log(this);  // window
    console.log(say.caller);
    console.log(arguments.callee.caller); //和上面代码一样,更友好，和函数名 say做了解耦
}

function add(a,b){
    let rs = 0;
    for (let index = 0; index < arguments.length; index++) {
        rs += arguments[index];
    }
    return rs;
}
add.apply(this,[1,4]);


var color = '全局Color';

var obj = {
    color : 'obj的Color'
}

function showColor(){
    console.log(this.color);
}

showColor.call(obj);
showColor.call(window);
showColor.call(this);

var objShowColor = showColor.bind(obj);
objShowColor()


var person = {
    name: "Nicholas",
    age: 29,
    job: "Software Engineer",
    sayName: function () {
        alert(this.name);
    }
};

Object.defineProperties(o,{
    _year:{value:2008}, 
    year:{
        get:function(){
            return  this._year
        },
        set: function(value){
            if (value > this._year){
                this._year = value
            }
        }
    }
})


function Person(name, age, job) {
    this.name = name;
    this.age = age;
    this.job = job;
    this.sayName = function () {
        alert(this.name);
    };
}
var person1 = new Person("Nicholas", 29, "Software Engineer");
var person2 = new Person("Greg", 27, "Doctor");

function Person() {
}
Person.prototype.name = "Nicholas";
Person.prototype.age = 29;
Person.prototype.job = "Software Engineer";
Person.prototype.sayName = function () {
    alert(this.name);
};
var person1 = new Person();
person1.sayName(); //"Nicholas"
var person2 = new Person();


function test(data){
	return new Promise((resolve, reject) => {		
		setTimeout(function(){
			
			if (data){
				resolve(users[0]);
			}else{
				reject();
			}
		},300);
	});	
}


function Animal(){
    this.animalName ='Animal'
    this.foods = ["鸟","爬行动物","植物"]
}

Animal.prototype.getAnimalName = function(){
    return this.animalName;
}

function Cat(){
    this.catName ='Cat';
}
//修改其原型
Cat.prototype = new Animal();
Cat.prototype.getCatName = function(){
    return this.catName;
}

var cat = new Cat();
var cat1 = new Cat();
console.log(cat1.foods);
cat.foods.push("鱼类");
console.log(cat1.foods);

cat.getAnimalName();    //Animal
cat.getCatName();       //Cat

Object.prototype.isPrototypeOf(cat);
Animal.prototype.isPrototypeOf(cat);
Cat.prototype.isPrototypeOf(cat);



function Animal(name){
    this.name = name;
    this.sayAtAnimal = function(){
        console.log('Animal-'+this.name);
    }
}

function Cat(name,age){
    Animal.call(this,name);
    this.age = age;
}

var cat = new Cat('卷毛',3);
cat.sayAtAnimal();

sayHello();
function sayHello(){
    alert('hi')
}

console.log(sayHello.name) // "sayHello"

var factorial = (function f(num) {
    if (num <= 1) {
        return 1;
    } else {
        return num * f(num - 1);
    }
});


function Person(){
    var age = 22;
    function printAge(){
        console.log(age);
    }

    this.getAge = function(){
        return age;
    }
}

var p = new Person();


function Person(name){
    this.getName = function(){
        return name;
    }
    this.setName = function(value){
        name = value;
    }
}

var p1 = new Person("Jack");
var p2 = new Person("Rose");



(function(){
    var age = 22;
    function printAge(){
        console.log("打印出",age)
    }
    //这里注意，没有使用 var 来申明 Person变量,那么Person 会成为全局变量
    Person = function(){

    }
    Person.prototype.getAge = function(){
        printAge();
        return age;
    }
})();


(function(){
    var age = 22;
    function printAge(){
        console.log(age);
    }

    //这里没有使用var 声明，将作为全局变量
    Person = function(){

    };

    Person.prototype.changeAge = function(){
        age ++;
        return printAge();
    }
})();

var p = new Person();
p.changeAge();


var getApp = (function(){
    var __obj = null;
    function Application(name){
        this.name = name;
        this.time = Date.now();
    }
    Application.prototype.print = function(){
        console.log(this.time);
    }
    if (!__obj){
        __obj = new Application('亿企代账');
    }
    return __obj;
})();

var getApp = function(){
    var __obj = null;
    function Application(name){
        this.name = name;
        this.time = Date.now();
    }
    Application.prototype.print = function(){
        console.log(this.time);
    }
    if (!__obj){
        __obj = new Application('亿企代账');
    }
    return __obj;
}();

